<?php

namespace app\common\model;

use joncc\attribute\Attribute;

class Docs
{
    public function doc($className): array
    {
        $doc = [];
        if (!class_exists($className)) {
            return $doc;
        }

        $instance = Attribute::instance()->make($className);
        $permissionList = $instance->permissionList();
        if (empty($permissionList)) {
            return $doc;
        }

        $doc = [
            'name' => $instance->name(),
            'comment' => $instance->comment(),
            'method' => [],
        ];

        $authNeedless = $instance->authNeedless();
        $permissionNeedless = $instance->permissionNeedless();

        foreach ($permissionList as $method => $comment) {
            $doc['method'][] = [
                'name' => $method,
                'comment' => $comment,
                'auth' => !deny($method, $authNeedless),
                'permission' => !deny($method, $permissionNeedless),
                'params' => $instance->methodParamsList($method),
            ];
        }

        return $doc;
    }
}